/*appBar样式-搜索 样式2：可选搜索类型*/
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:frametrim/utility/screen.dart';
import 'package:frametrim/utility/sq_color.dart';
import 'package:frametrim/utility/toast.dart';
import 'package:frametrim/views/textfiled_text.dart';

/*如果   hasBack的话必须要传入imgStr
*  使用时候需要用Scaffold包裹*/
@immutable
class AppbarSearchSeconedTitle extends StatelessWidget implements PreferredSizeWidget {
  final bool hasBack;
  final double? height;
  final String? imgStr;

  //有的标题只需要点击跳转  不具有编辑功能
  final bool isNeedJump;
  final TextEditingController controller;
  final Function(String) callback;

  AppbarSearchSeconedTitle(
      {Key? key,
      this.hasBack = true,
      required this.controller,
      required this.callback,
      required this.imgStr,
      this.isNeedJump = false,
      this.height = 45})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      margin: EdgeInsets.only(top: 10),
      color: Colors.white,
      // color: Colors.white,
      width: Screen.width,
      height: height! + Screen.topSafeHeight,
      padding: EdgeInsets.fromLTRB(0, Screen.topSafeHeight, 0, 0),
      child: Stack(
        alignment: Alignment.center,
        children: [
          hasBack
              ? Positioned(
                  left: 0,
                  child: IconButton(
                      onPressed: () {
                        Navigator.pop(context);
                      },
                      icon: Container(
                        width: height,
                        height: height,
                        padding: EdgeInsets.fromLTRB(0, 8, 0, 8),
                        child: Image.asset(
                          imgStr!,
                        ),
                      )),
                )
              : Container(),
          Row(


          ),







        ],
      ),
    );
  }

  Widget buildkuang() {
    return Container(
      height: 35,
      padding: EdgeInsets.only(left: 10, right: 10),
      margin: EdgeInsets.only(right: 15, left: 45),
      decoration: BoxDecoration(
          border: Border.all(color: SQColor.color_3C64F9, width: 1),
          borderRadius: BorderRadius.all(Radius.circular(20))),
      child: Row(
        children: [
          Image.asset(
            'image/icon_search.png',
            width: 20,
            height: 20,
          ),
          SizedBox(
            width: 5,
          ),
          Expanded(
              child: TextField(
            enabled: !isNeedJump,
            maxLength: 50,
            //键盘样式
            // keyboardType: TextInputType.text,
            controller: controller,
            textInputAction: TextInputAction.search,
            onSubmitted: (str) {
              if (controller.text.isEmpty) {
                ToastUtils.show('请输入搜索内容');
                return;
              }
              callback(controller.text);
            },
            decoration: InputDecoration(
              counterText: '',
              contentPadding: EdgeInsets.symmetric(vertical: 0),
              border: OutlineInputBorder(borderSide: BorderSide.none),
              hintText: '请输入搜索内容',
              hintStyle: TextStyle(fontSize: 15, color: SQColor.color_888888),
              labelStyle: TextStyle(fontSize: 15, color: SQColor.black),
            ),
          )),
          SizedBox(
            width: 10,
          ),
          GestureDetector(
            child: Text(
              '搜索',
              style: TextStyle(fontSize: 15, color: SQColor.color_3C64F9),
            ),
            onTap: () {
              if (isNeedJump) {
                callback('');
              } else {
                if (controller.text.isEmpty) {
                  ToastUtils.show('请输入搜索内容');
                  return;
                }
                callback(controller.text);
              }
            },
          ),
        ],
      ),
    );
  }

  @override
  Size get preferredSize => Size.fromHeight(height!);
}
